package com.GamersCom.model;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.GamersCom.db.Game;
import com.GamersCom.db.GameDAO;
import com.GamersCom.db.Genre;

public class GameMgr
{
	GameDAO dao = new GameDAO();
	
	public void insert (Game game) throws SQLException
	{
		String query = "insert into games (name,company,summary,website,releaseDate,platform,genre) values (?,?,?,?,?,?,?)";
		List paramList = new ArrayList();
		paramList.add(game.getName());
		paramList.add(game.getCompany());
		paramList.add(game.getSummary());
		paramList.add(game.getWebsite());
		paramList.add(game.getReleaseDate());
		paramList.add(game.getPlatform());
		paramList.add(game.getGenre());
		
		dao.insert(query, paramList);
	}
	
	public void delete(Game game) throws SQLException 
	{
		String query = "delete from games where id = ?";
		List paramList = new ArrayList();
		paramList.add(game.getId());
		
		dao.delete(query, paramList);
	}
	
	public void update(Game game) throws SQLException 
	{
		String query = "update games set name = ?, company =?, website =?, releaseDate=?, summary=?,platform=?,genre=? where id = ?";
		List paramList = new ArrayList();
		paramList.add(game.getName());
		paramList.add(game.getCompany());
		paramList.add(game.getWebsite());
		paramList.add(game.getReleaseDate());
		paramList.add(game.getSummary());
		paramList.add(game.getPlatform());
		paramList.add(game.getGenre());
		paramList.add(game.getId());
		
		dao.update(query, paramList);
	}
	public List<Game> getAllGames() throws SQLException
	{
		String query = "select * from games";
		
		return dao.getAll(query);
	}
	
	public List<Game> getAllByPf(String pf) throws SQLException
	{
		String query = "select * from games where platform = '"+pf+"'";
		return dao.getAll(query);
	}
	
	public Game getGameById(int id) throws SQLException
	{
		String query = "select * from games where id = " + id ;
		if ( dao.getAll(query) == null )
		{
			return null;
		}
		
		return dao.getAll(query).get(0);
	}
}
